<?php
include_once "db.php";
include_once "checksession.php"; 
include_once "auth_permissions.php";
authorize("user");

 class Pager  
   {  
       function getPagerData($numHits, $limit, $page)  
       {  
           $numHits  = (int) $numHits;  
           $limit    = max((int) $limit, 1);  
           $page     = (int) $page;  
           $numPages = ceil($numHits / $limit);  

           $page = max($page, 1);  
           $page = min($page, $numPages);  

           $offset = ($page - 1) * $limit;  

           $ret = new stdClass;  

           $ret->offset   = $offset;  
           $ret->limit    = $limit;  
           $ret->numPages = $numPages;  
           $ret->page     = $page;  

           return $ret;  
       }  
   }  

 // get the pager input values  
    $page = $_GET['page'];  
	$limit = 50;  
	$callsresults = mysql_query("select count(*) from Calls WHERE Calls.call_closed='$_GET[active]' ");  
	$total = mysql_result($callsresults, 0, 0);  
	$callsresults2 = mysql_query("select * from Calls WHERE Calls.call_closed=2 ");  
	$total2 = mysql_num_rows($callsresults2);

    // work out the pager values  
    $pager  = Pager::getPagerData($total, $limit, $page);  
    $offset = $pager->offset;  
    $limit  = $pager->limit;  
    $page   = $pager->page;  

    // use pager values to fetch data  
	
	
if (is_numeric($_GET[active]))
$calls = mysql_query("select Calls.*, problem_type.PT_desc from Calls,problem_type where Calls.problem_type = problem_type.PT_ID AND Calls.call_closed='$_GET[active]'  ORDER BY Calls.request_date DESC limit $offset, $limit");
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Online College Helpdesk - Calls</title>
<link href="meta-style.css" rel="stylesheet" type="text/css" />
</head>

<body>
<?php

include_once "topnav.php";

if (($_GET[active]) == 1)
	echo '<p class=title>Active Entries</p>';
else
	echo '<p class=title>Inactive Entries</p>';


	
$start = 1;
$end = $pager->numPages;
$cur = $pager->page;
if ($pager->numPages > 21)
{
	$start = $cur - 10;
	$end = $cur + 10;
	if ($start < 1)
	{
		$end = $end + (1 - $start);
		$start = 1;
	}
	if ($end > $pager->numPages)
	{
		$start = $start - ($end - $pager->numPages);
		$end = $pager->numPages;
	}
}
if ($start > 1)
	echo "<a href=\"calls.php?page=1&active={$_GET[active]}\">Newest</a>";

echo "<span class=normal>|</span>";
	
$page = $start;
while ($page <= $end)
{

	if ($page == $cur) 
		echo "<font color=\"red\">Page {$page}</font>";
	else  
		echo "<a href=\"calls.php?page={$page}&active={$_GET[active]}\">{$page}</a>";
	echo "<span class=normal>|</span>";
	$page++;
}
if ($end < $pager->numPages)
	echo "<span class=normal><a href=\"calls.php?page={$pager->numPages}&active={$_GET[active]}\">Oldest</a></span>"

?>
<br>
<br>

<table width="50%" align="center" border="1" cellpadding="5" cellspacing="0" bordercolor="#666666">
  <tr>
  <td width="20%" rowspan="2" align="center" valign="middle"><strong>White = Untouched</strong></td>
    <td width="20%" rowspan="2" align="center" valign="middle" bgcolor="#6DB2F2"><strong>Intern  Needs Followup </strong></td>
    <td width="20%" rowspan="2" align="center" valign="middle" bgcolor="#FFF68F"><strong>Pending Info From Student </strong></td>
    <td width="20%" rowspan="2" align="center" valign="middle" bgcolor="#00C78C"><strong>Supervisor Needs Followup </strong></td>
    <td width="20%" rowspan="2" align="center" valign="middle" bgcolor="#FF9900"><strong>Higher Level Ticket</strong></td>
  </tr>
  <tr></tr>
  
  <!--<tr>
    <td colspan="5"><p class="style2">&nbsp;</p>
    </td>
  </tr>!-->
</table>

<div align="center" style="padding:10px">
	<span style="font-size:14px; color:#990000; font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold">
		<strong>
			Total 
			<?php 
				if ($_GET[active] == 1)
					echo "Open";
				else
					echo "Closed";
			?>
			Tickets = 
		</strong>
	</span>
	<span style="font-size:14px; color:#990000; font-family:Verdana, Arial, Helvetica, sans-serif; font-weight:bold">
		<?php echo $total; ?>
	</span>
</div>
<table width="100%" border="1" cellpadding="3" cellspacing="0" bordercolor="#666666" align="center">
 <tr align="center" bgcolor=#999999>
     <td width="48"><strong>Ticket # </strong></td>
     <td width="115"><strong>First Name </strong></td>
    <td width="115"><strong>Last Name </strong></td>
    <td width="174"><strong>Email</strong></td>
    <td width="269"><strong>Problem Type </strong></td>
    <td width="109"><strong>Date/Time of Call </strong></td>
    <td width="49"><strong>Left VM</strong></td>
	 <td width="111"><strong>Action</strong></td>
  </tr>
 <?php 
		 if ($calls > 0) 
		 while($callsresults = mysql_fetch_array($calls)) {
		 $date = substr($callsresults[request_date],5,2)."/".substr($callsresults[request_date],8,2)."/".substr($callsresults[request_date],0,4)."-".substr($callsresults[request_date],10,6);
		 if ($callsresults[higher_level]==1){
		 $bgcolor="#FF9900" ;
		 }else if ($callsresults[oia_followup]==1) {
		 $bgcolor="#6DB2F2" ;
		 }else if ($callsresults[hl_followup]==1) {
		 $bgcolor="#00C78C" ;
		 }else if ($callsresults[pending]==1) {
		 $bgcolor="#FFF68F" ;
		 }else {
		 $bgcolor="#FFFFFF";
		 }
		 echo "<tr bgcolor=".$bgcolor." align=left> \n";
		 echo "<td>" . $callsresults[Call_ID] ."&nbsp;</td> \n";
		 echo "<td>" . $callsresults[first_name] ."&nbsp;</td> \n";
		 echo "<td>" . $callsresults[last_name] ."&nbsp;</td> \n";
		 echo "<td>" . $callsresults[email]."&nbsp;</td> \n";
		 echo "<td>" . $callsresults[PT_desc]."&nbsp;</td> \n";
		 echo "<td>" . $date."&nbsp;</td> \n";
 		 echo "<td>" . (($callsresults[left_mssg] == 2) ? "no" : "yes" )."&nbsp;</td> \n";
		 //checking to see if user is an admin
		 echo "<td><a href=calls_detail.php?callid=" . $callsresults[Call_ID] .">Details</a> \n";
		 if (auth_check('admin')){
  		 echo "|<a href=delete_call.php?callid=" . $callsresults[Call_ID] .">Delete Call</a> \n";
		 }
		 echo "</td></tr> \n";
	 
		  }
		 else 
		 echo "<span class=normal><strong>There are no active records...</strong></span>";	
		 
	     ?> 
</table>


<p><a href="index.php">Back to Main Menu</a></p>
</body>
</html>
